

import org.apache.log4j.Logger;

//import java.util.ArrayList;

 
public class CompareOutline {
	//private static SqlInterface objSql;
	
	static Logger logger = Logger.getLogger("CompareOutline");	 
	
	public static void  outDimensions(EssGetOutline objDatabaseOutline)
	{
		System.out.println(objDatabaseOutline.getOlapServer() + " " + objDatabaseOutline.getApplication()   + " " +  objDatabaseOutline.getDatabase()  + " " +  "\n" ); 
		for (ObjDimension currObjDimensions : objDatabaseOutline.getArrDimemnsions()) {
			System.out.println(currObjDimensions.getDimensionName() + "\n" );
	      }
			
	}
	
	public static void  outLoginErrors ( )
	{
		System.out.println("Please provide logon information to Essbase Database like" +
		" Otl1=user_name/password@Server'Application'Database  Otl2=user_name/password@Server'Application'Database   ");	

			
	}

	public static EssGetOutline  commectToEssOutline  ( String strConnString ) throws Exception //Otl1=user_name/password@Server'Application'Database
	{
		
		if  (!("").equals(strConnString.split("=")[1]))
		{
		String  strOtl=strConnString.split("=")[1];
		 
		if  (!("").equals(strOtl.split("/")[0])) {
		String  strOtlUserName=strOtl.split("/")[0];
		 
		if ( !("").equals(strOtl.split("/")[1].split("@")[0])) {		
		String  strOtlPassword=strOtl.split("/")[1].split("@")[0];
		 
		if ( !("").equals(strOtl.split("/")[1].split("@")[1])) {	
		String  strOtlApplication=strOtl.split("/")[1].split("@")[1];
		 
		if ( !("").equals(strOtlApplication.split("'")[0])) {	
		String  strOtlServer=strOtlApplication.split("'")[0];
		 
		if ( !("").equals(strOtlApplication.split("'")[2])) {	
		String  strOtlDatabase=strOtlApplication.split("'")[2];
		 
		if ( !("").equals(strOtlApplication.split("'")[1])) { 	
				strOtlApplication=strOtlApplication.split("'")[1];	
		 
			
	  Integer intCheckLoginInformation =  strOtlUserName.length() * strOtlPassword.length() * strOtlApplication.length() * strOtlDatabase.length();		

		if ( intCheckLoginInformation == 0 ) {
			outLoginErrors ( );
			}
		else {
			// System.out.println(strOtlUserName + " " + strOtlPassword + " " + strOtlServer + " " + strOtlApplication + " " + strOtlDatabase + "\n" );		
		return new EssGetOutline(strOtlUserName, strOtlPassword, strOtlServer,strOtlApplication, strOtlDatabase, "embedded");

		} } } } } } } }
		outLoginErrors ( );
		return null; 
			
	}
	
static Thread runEssGetOutline (final EssGetOutline objOtl)
	{
		Thread t = new Thread(new Runnable(){
		    public void run(){
		    	try {
		    		objOtl.EssGetOutlineRun();
				} catch (Exception e) {
					e.printStackTrace();					
				}
		    }
		});
		t.start();
		return t;
	}
	
	public static void main(String[] args) throws Exception {
		
/*
 *  
 * 		Outl1 
 *   CompareOutline  Otl1=user_name/password@Application:Database Otl2=user_name/password@Application:Database      	

*/
			
 	 if ( args.length != 2  ) {
 		outLoginErrors();
		 }
		 else { 			
		final EssGetOutline objOtl1 = commectToEssOutline(args[0]);
		if ( null != objOtl1 ) {
		final EssGetOutline objOtl2 = commectToEssOutline(args[1]);
		if ( null != objOtl2 ) {
	//	final EssGetOutline objOtl2 = new EssGetOutline("Admin", "password", "localhost", "Sample2", "Basic2", "embedded");
	
		Thread t1=runEssGetOutline(objOtl1);
		Thread t2=runEssGetOutline(objOtl2);
		
		t1.join();
		t2.join();
		

		EssToSqlWorkFlow.getMissingDimensions( objOtl1.getOtlDimensionTableName(), objOtl2.getOtlDimensionTableName(), ".//");
		EssToSqlWorkFlow.getDifferentsFromDim ( objOtl1.getOtlDimensionTableName(), objOtl2.getOtlDimensionTableName(), ".//");
		
		EssToSqlWorkFlow.getMissingDimensions( objOtl1.getOtlDimensionTableName(), objOtl2.getOtlDimensionTableName(), ".//");
		EssToSqlWorkFlow.getDifferentsFromDim ( objOtl1.getOtlDimensionTableName(), objOtl2.getOtlDimensionTableName(), ".//");
		 
		}
		}
	}  
			
	}// main(String[] args) throws Exception  
	
}// public class CompareOutline {
